package org.example.Controller;

import jakarta.annotation.Resource;
import org.example.common.Result;
import org.example.common.ResultCodeEnum;
import org.example.pojo.Business;
import org.example.pojo.Query;
import org.example.service.BusinessService;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/Business")
public class BusinessController {

    @Resource
    private BusinessService businessService;
    @PostMapping("/list")
    public Result list(@RequestBody Query query){
     Result result= businessService.searchlist(query);
return result;

    }
    @PostMapping("/add")
    public Result add(@RequestBody Business business){
        if(business.getId()!=null){
            Result result=businessService.updatebus(business);
            return result;
        }else{
            Result result=businessService.add(business);
            return result;
        }
    }
    @PostMapping("/delete")
    public Result deleteById(Integer id){
        if(id== null){
            return Result.build("请输入ID", ResultCodeEnum.ID_ERROR);
        }
            businessService.deleteById(id);
            return Result.ok("删除成功");

    }
    @PostMapping("/update")
    public Result update(@RequestBody Business business){
        Result result=businessService.updateperson(business);
        return result;
    }
    @PostMapping("/updatePassword")
    public Result updatePassword(@RequestBody Business business){
        Result result=businessService.updatepassword(business);
        return result;
    }
    @GetMapping("/all")
    public Result getall(){

        Result result=businessService.getall();
        return result;
    }
    @PostMapping("/detail")
    public Result getdetail(Integer id){
        Result result=businessService.getdetail(id);
        return result;
    }



}
